<div class="layui-form">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">日期</label>
      <div class="layui-input-inline">
        <input type="text" class="layui-input" id="dateInput" placeholder="yyyy-MM-dd">
      </div>
    </div>
  </div>
</div>
<script src="https://www.layuicdn.com/layui/layui.js"></script>
<script type="text/javascript">
    layui.use('laydate', function(){
        var laydate = layui.laydate;
            laydate.render({
                elem: '#dateInput',
                value: '{{ $compareDate }}',
                isInitValue: true,
                done: function(value, date){
                    setCompareDate(value)
                }
            });
    })

    function setCompareDate(date){
        console.log(date)
        let url = "{{ URL::asset('admin/setCompareDate') }}";
        let data = {
            _token: '{{ csrf_token() }}',
            date: date
        }
        $.ajax({
            type : "POST",
            url : url,
            data : data,
            success : function(result) {
                console.log(result)
                if (result.code == 1) {
                    location.reload();
                } else {
                    console.log(result.msg)
                }
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                layer.close(e);
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }
</script>